package clickhouse_tb

import (
	"sync"
	"wx-api/adx-bid/config"
	"wx-api/adx-bid/models/bid/BidModel"
)

var AdxMsgCk = &CkADB{
	Table:        config.CkTableReport,
	SqlStr:       "",
	Fields:       []string{"date", "date_hour", "bidid", "syst", "adx_id", "media_id", "slot_id", "plan_id", "dsp_id", "pos_id", "req", "fill", "dsp_req", "dsp_fill", "mon", "pv", "ipv", "click", "iclick", "video_start", "video_end", "download_start", "download_end", "install_start", "install_end", "activation", "deeplink", "ideeplink", "adx_price", "dsp_price", "cost"},
	BulkLen:      10000,
	FlushTime:    10,
	Mux:          new(sync.Mutex),
	Execution_id: 1,
	Events:       make([][]interface{}, 0),
}

func AdxMsgSend(msg *BidModel.LogMsg) {
	if msg.GetDate() == "" || msg.GetDateHour() == "" {
		return
	}
	event := AdxMsgData(msg)
	AdxMsgCk.Emit(event)
}

// 数据
func AdxMsgData(e *BidModel.LogMsg) []interface{} {
	ret := []interface{}{}
	ret = append(ret, e.GetDate())
	ret = append(ret, e.GetDateHour())
	ret = append(ret, e.GetBidid())
	ret = append(ret, e.GetSyst())
	ret = append(ret, e.GetAdxId())
	ret = append(ret, e.GetMediaId())
	ret = append(ret, e.GetSlotId())
	ret = append(ret, e.GetPlanId())
	ret = append(ret, e.GetDspId())
	ret = append(ret, e.GetPosId())
	ret = append(ret, e.GetReq())
	ret = append(ret, e.GetFill())
	ret = append(ret, e.GetDreq())
	ret = append(ret, e.GetDfill())
	ret = append(ret, e.GetMon())
	ret = append(ret, e.GetPv())
	ret = append(ret, e.GetIpv())
	ret = append(ret, e.GetClick())
	ret = append(ret, e.GetIclick())
	ret = append(ret, e.GetVideoStart())
	ret = append(ret, e.GetVideoEnd())
	ret = append(ret, e.GetDownloadStart())
	ret = append(ret, e.GetDownloadEnd())
	ret = append(ret, e.GetInstallStart())
	ret = append(ret, e.GetInstallEnd())
	ret = append(ret, e.GetActivation())
	ret = append(ret, e.GetDeeplink())
	ret = append(ret, e.GetIdeeplink())
	ret = append(ret, e.GetMediaPrice()) //返回给媒体价格
	ret = append(ret, e.GetDspPrice())   //上游返回价格
	ret = append(ret, e.GetCost())       //自有价格
	return ret
}
